<?php

namespace App\Models\Entity\Pm;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * Class Pmtag
 * @package App\Models\Entity\Pm
 * @version August 1, 2017, 4:33 pm UTC
 */
class Pmtag extends Model
{
    use SoftDeletes;

    public $table = 'pmtags';

    protected $dates = ['deleted_at'];
    
    public $fillable = [
        'name',
        'title',
        'subtitle',
        'short_desc',
        'images',
        'created_at',
        'updated_at',
        'online_at',
        'offline_at',
        'status',
        'keyword',
    ];

    /**
     * The attributes that should be casted to native types.
     *
     * @var array
     */
    protected $casts = [
        'name'       => 'string',
        'title'      => 'string',
        'subtitle'   => 'string',
        'short_desc' => 'string',
        'images'     => 'string',
        'status'     => 'string',
        'keyword'     => 'string',
    ];

    /**
     * Validation rules
     *
     * @var array
     */
    public static $rules = [
        'name'       => 'required|max:100',
        'title'      => 'max:100',
        'short_desc' => 'required|max:100',
        'images'     => 'max:200',
    ];

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     **/
    public function meteringPeriods()
    {
        return $this->hasMany(\App\Models\Entity\Pm\MeteringPeriod::class, 'id', 'metering_period_id');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     **/
    public function vassetis()
    {
        return $this->belongsToMany(\App\Models\Entity\Asset\Video\Vasseti::class, 'pmtag_vassetis', 'pmtag_id', 'vasseti_id');
    }
    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function sps()
    {
        return $this->belongsToMany(\App\Models\Common\EntityData\Channel\Sp::class, 'pmtag_sps', 'pmtag_id', 'sp_id');
    }
}
